<template>
	<view>
		<view class="notice-item">
			<u-swipe-action>
				<view class="" v-for="(item,index) in noticeData" :key="index">
					<u-swipe-action-item :options="options1" @click='delData(item.id)'>
						<text class="time">{{item.time}}</text>
						<view class="content">
							<view class="contentTop">
								<text class="title">{{item.type}}</text>
								<u-badge :isDot="true" :type="item.read==0?'error':'success'"></u-badge>
							</view>
							<view class="img-wrapper">
								<view class="cover">
									{{item.type}}
								</view>
							</view>
							<text class="introduce">{{item.cause}}</text>
						</view>
					</u-swipe-action-item>
				</view>
			</u-swipe-action>

		</view>
	</view>
</template>

<script>
	import {
		messageCenterStatus,
		messageCenterList,
		messageCenterDelete
	} from '@/api/userCenter.js'
	export default {
		data() {
			return {
				noticeData: [],
				options1: [{
					text: '删除',
					style: {
						backgroundColor: 'red',
					}
				}]
			}
		},
		methods: {
			async delData(id) {
				let res = await messageCenterDelete(id)
				if (res.code == 200) {
					wx.showToast({
						title: '删除成功',
						icon: 'success',
						duration: 1000
					})
					this.getList()
				}
			},
			async getList() {
				let res = await messageCenterList()
				if (res.code == 200) {
					this.noticeData = res.data
				}
			},
			async getMessageCenterStatus() {
				let res = await messageCenterStatus()
			},
		},
		onShow() {
			this.getList()
			setTimeout(res => {
				this.getMessageCenterStatus()
			}, 100)
		}
	}
</script>

<style lang='scss'>
	page {
		background-color: #f7f7f7;
		padding-bottom: 30upx;
	}

	.notice-item {
		display: flex;
		flex-direction: column;
		align-items: center;
	}

	.time {
		display: flex;
		align-items: center;
		justify-content: center;
		height: 80upx;
		padding-top: 10upx;
		font-size: 26upx;
		color: #7d7d7d;
	}

	.content {
		width: 710upx;
		padding: 0 24upx;
		background-color: #fff;
		border-radius: 4upx;
	}

	.contentTop {
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.title {
		display: flex;
		align-items: center;
		height: 90upx;
		font-size: 32upx;
		color: #303133;
	}

	.img-wrapper {
		width: 100%;
		height: 260upx;
		position: relative;
	}

	.pic {
		display: block;
		width: 100%;
		height: 100%;
		border-radius: 6upx;
	}

	.cover {
		display: flex;
		justify-content: center;
		align-items: center;
		position: absolute;
		left: 0;
		top: 0;
		width: 100%;
		height: 100%;
		background-color: rgba(0, 0, 0, .5);
		font-size: 36upx;
		color: #fff;
	}

	.introduce {
		display: inline-block;
		padding: 16upx 0;
		font-size: 28upx;
		color: #606266;
		line-height: 38upx;
	}

	.bot {
		display: flex;
		align-items: center;
		justify-content: space-between;
		height: 80upx;
		font-size: 24upx;
		color: #707070;
		position: relative;
	}

	.more-icon {
		font-size: 32upx;
	}
</style>